//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.lyn.serialPort;

import android.util.Log;

import java.io.File;
import java.util.ArrayList;

public class Driver {
    private static final String TAG = Driver.class.getSimpleName();
    private String mDriverName;
    private String mDeviceRoot;

    public Driver(String name, String root) {
        this.mDriverName = name;
        this.mDeviceRoot = root;
    }

    public ArrayList<File> getDevices() {
        ArrayList<File> devices = new ArrayList();
        File dev = new File("/dev");
        if (!dev.exists()) {
            Log.i(TAG, "getDevices: " + dev.getAbsolutePath() + " 不存在");
            return devices;
        } else if (!dev.canRead()) {
            Log.i(TAG, "getDevices: " + dev.getAbsolutePath() + " 没有读取权限");
            return devices;
        } else {
            File[] files = dev.listFiles();

            for(int i = 0; i < files.length; ++i) {
                if (files[i].getAbsolutePath().startsWith(this.mDeviceRoot)) {
                    Log.d(TAG, "Found new device: " + files[i]);
                    devices.add(files[i]);
                }
            }

            return devices;
        }
    }

    public String getName() {
        return this.mDriverName;
    }
}
